<%@page import="java.util.ArrayList"%>
<%@page import="java.util.UUID"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="java.util.List"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="java.util.Date,java.io.*"%>
<%@page import="cn.school.servies.*,cn.school.entity.*,java.text.*"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="includ.jsp" %>
 <%!
int a;
%>
<%
/* request.setCharacterEncoding("utf-8");
String sname=request.getParameter("sname");
String sex=request.getParameter("sex");
String telephone=request.getParameter("telephone");
String qq=request.getParameter("qq");
String wechat=request.getParameter("wechat");
long gradeid=Long.parseLong(request.getParameter("gradeid"));
String enterdate=request.getParameter("enterdate");
String fromcity=request.getParameter("fromcity");
String birthday=request.getParameter("birthday");
String address=request.getParameter("address");
String pass=request.getParameter("pass");
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
Date enter=format.parse(enterdate);
Date birth=format.parse(birthday); */

/* Student stu=new Student();
stu.setSname(sname);
stu.setSex(sex);
stu.setTelephone(telephone);
stu.setGradeid(gradeid);
stu.setQq(qq);
stu.setWechat(wechat);
stu.setEnterdate(enter);
stu.setFromcity(fromcity);
stu.setBirthday(birth);
stu.setAddress(address);
stu.setPass(pass);
out.print(stu);
 StudentSerive serive=new StudentSerive();
a=serive.add(stu);  */ 
%>


<!-- 接收文本文件 -->
<%-- <%
 InputStream in=request.getInputStream();
 int ch=0;
 while((ch=in.read())!=-1){
	 out.print((char)ch);
 }
%> --%>
<%

DiskFileItemFactory factory = new DiskFileItemFactory(); 
//设置缓冲区大小 
factory.setSizeThreshold(1024 * 100); 
//设置临时文件路径 
//factory.setRepository(tempFile); 
//创建文件上传处理器 
ServletFileUpload upload = new ServletFileUpload(factory); 
upload.setHeaderEncoding("utf-8");

List<FileItem> list=upload.parseRequest(request);

Student stu=new Student();

List<String> xinxi=new ArrayList();
for(FileItem f:list){

%>
<p>
<%
if(f.isFormField()){
	out.print("这是表单元素："+f.getFieldName()+",值是："+f.getString("utf-8"));
	xinxi.add(f.getString("utf-8"));
	
}else{
	out.print("这是文件元素");
	if(f.getSize()==0){
		continue;
	}
	out.print("文件名："+f.getName()+"元素名"+f.getFieldName());
	File path=new File("E:\\新建文件夹\\JAVA应用\\新建文件夹 (2)\\JavaWeb12-4\\WebContent\\imges");
	

	
	if(path.exists()==false){
		path.mkdir();
	}
	out.print(application.getRealPath("imges")+"---");
	String suffix=f.getName().substring(f.getName().lastIndexOf("."));
	String newname=UUID.randomUUID()+suffix;
	f.write(new File(path,newname));
	
	stu.setPhoto("imges/"+newname);
}

%>
<%}
stu.setSname(xinxi.get(0));
stu.setSex(xinxi.get(1));
System.out.println("sxex=========="+stu.getSex());
stu.setTelephone(xinxi.get(2));
stu.setQq(xinxi.get(3));
stu.setWechat(xinxi.get(4));
stu.setGradeid(Long.parseLong(xinxi.get(5)));
String enter=xinxi.get(6);
 SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
 Date enterdate= format.parse(enter);
 if(enterdate!=null)
 stu.setEnterdate(enterdate);
 stu.setFromcity(xinxi.get(7));
 String birth=xinxi.get(8);
 Date birthday= format.parse(birth);
 stu.setBirthday(birthday);
 stu.setAddress(xinxi.get(9));
 stu.setPass(xinxi.get(10));
 StudentSerive serive=new StudentSerive();
 a=serive.add2(stu);
%>
天加了<%=a %>名学生 
</p>
</body>
</html>